package cn.homework.day08;

import java.util.*;

public class Test09 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        ArrayList<Student> list1 = new ArrayList<>();
        ArrayList<String> list2 = new ArrayList<>();
        TreeMap<Student, String> map = new TreeMap<>(new Comparator<Student>() {
            // 要求map集合中不能存在相同的学生信息.并按照学生年龄降序排列
            @Override
            public int compare(Student o1, Student o2) {
                if (o1.getName().equals(o2.getName()) && o1.getAge() == o2.getAge()) {
                    return 0;
                }
                return o2.getAge() - o1.getAge();
            }
        });
        int index = 0;
        while (index < 3) {
            System.out.println("请输入第" + (index + 1) + "个学生姓名");
            String name = sc.next();
            System.out.println("请输入第" + (index + 1) + "个学生年龄");
            int age = sc.nextInt();
            System.out.println("请输入第" + (index + 1) + "个学生居住地");
            String address = sc.next();
            list1.add(new Student(name, age));
            list2.add(address);
            index++;
        }
        for (int i = 0; i < 3; i++) {
            map.put(list1.get(i), list2.get(i));
        }
        //使用Stream流输出集合中所有姓张的人信息;
        map.keySet().stream().filter(student -> student.getName().startsWith("张")).forEach(System.out::println);


    }
}
